package com.fr.chart.shape3d;

import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLReadable;
import com.fr.base.xml.XMLableReader;
import com.fr.chart.ColorInfo;
import com.fr.chart.base.equals.Equals;
import com.fr.chart.core.glyph.SoloGlyph;
import com.fr.chart.math.Object3D;
import com.fr.chart.math.Projection;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.GeneralPath;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Pie3D extends SoloGlyph
  implements Object3D
{
  private static final long serialVersionUID = 4123668892673753116L;
  public static final String XML_TAG = "Pie3D";
  private Projection projection = new Projection();
  private List cylinderList = new ArrayList();

  public void draw(Graphics paramGraphics)
  {
    Cylinder localCylinder;
    Object localObject1;
    Object localObject2;
    Color localColor;
    Graphics2D localGraphics2D = (Graphics2D)paramGraphics;
    for (int i = 0; i < getCylinderCount(); ++i)
    {
      localCylinder = getCylinder(i);
      localObject1 = localCylinder.getColorInfo();
      localObject2 = ((ColorInfo)localObject1).getSeriesColor();
      if (localObject2 != null)
        ((ColorInfo)localObject1).setSeriesColor(((Color)localObject2).darker());
      ((ColorInfo)localObject1).paint(localGraphics2D, localCylinder.bottom());
      ((ColorInfo)localObject1).setSeriesColor((Color)localObject2);
    }
    for (i = 0; i < getCylinderCount(); ++i)
    {
      localCylinder = getCylinder(i);
      localObject1 = localCylinder.getColorInfo();
      localObject2 = ((ColorInfo)localObject1).getSeriesColor();
      if (localObject2 != null)
        ((ColorInfo)localObject1).setSeriesColor(((Color)localObject2).darker());
      ((ColorInfo)localObject1).paint(localGraphics2D, localCylinder.back());
      ((ColorInfo)localObject1).setSeriesColor((Color)localObject2);
    }
    Cylinder.CylinderSide[] arrayOfCylinderSide = new Cylinder.CylinderSide[getCylinderCount() * 2];
    for (int j = 0; j < getCylinderCount(); ++j)
    {
      arrayOfCylinderSide[(2 * j)] = new Cylinder.CylinderSide(getCylinder(j), true);
      arrayOfCylinderSide[(2 * j + 1)] = new Cylinder.CylinderSide(getCylinder(j), false);
    }
    Arrays.sort(arrayOfCylinderSide);
    for (j = 0; j < arrayOfCylinderSide.length; ++j)
    {
      localObject1 = arrayOfCylinderSide[j].cylinder;
      localObject2 = ((Cylinder)localObject1).getColorInfo();
      localColor = ((ColorInfo)localObject2).getSeriesColor();
      if (localColor != null)
        ((ColorInfo)localObject2).setSeriesColor(localColor.darker());
      if (arrayOfCylinderSide[j].isStart)
        ((ColorInfo)localObject2).paint(localGraphics2D, ((Cylinder)localObject1).getStartSide());
      else
        ((ColorInfo)localObject2).paint(localGraphics2D, ((Cylinder)localObject1).getEndSide());
      ((ColorInfo)localObject2).setSeriesColor(localColor);
    }
    for (j = 0; j < getCylinderCount(); ++j)
    {
      localObject1 = getCylinder(j);
      localObject2 = ((Cylinder)localObject1).getColorInfo();
      ((ColorInfo)localObject2).paint(localGraphics2D, ((Cylinder)localObject1).front());
    }
    for (j = 0; j < getCylinderCount(); ++j)
    {
      localObject1 = getCylinder(j);
      localObject2 = ((Cylinder)localObject1).getColorInfo();
      localColor = ((ColorInfo)localObject2).getSeriesColor();
      if (localColor != null)
        ((ColorInfo)localObject2).setSeriesColor(localColor.brighter());
      ((ColorInfo)localObject2).paint(localGraphics2D, ((Cylinder)localObject1).top());
      ((ColorInfo)localObject2).setSeriesColor(localColor);
    }
  }

  public Shape getShape()
  {
    GeneralPath localGeneralPath = new GeneralPath();
    for (int i = 0; i < getCylinderCount(); ++i)
      localGeneralPath.append(getCylinder(i).getShape(), false);
    return localGeneralPath;
  }

  public void addCylinder(Cylinder paramCylinder)
  {
    this.cylinderList.add(paramCylinder);
  }

  public Cylinder getCylinder(int paramInt)
  {
    return ((Cylinder)this.cylinderList.get(paramInt));
  }

  public int getCylinderCount()
  {
    return this.cylinderList.size();
  }

  public Projection getProjection()
  {
    return this.projection;
  }

  public void setProjection(Projection paramProjection)
  {
    this.projection = paramProjection;
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isChildNode())
    {
      String str = paramXMLableReader.getTagName();
      if (str.equals("Projection"))
        setProjection((Projection)paramXMLableReader.readXMLObject(new Projection()));
      else if (str.equals("List"))
        paramXMLableReader.readXMLObject(new XMLReadable(this)
        {
          private final Pie3D this$0;

          public void readXML()
          {
            String str = paramXMLableReader.getTagName();
            if (str.equals("Cyliner"))
              this.this$0.addCylinder((Cylinder)paramXMLableReader.readXMLObject(new Cylinder()));
          }
        });
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("Pie3D");
    if (this.projection != null)
      this.projection.writeXML(paramXMLPrintWriter);
    if ((this.cylinderList != null) && (this.cylinderList.size() > 0))
    {
      paramXMLPrintWriter.startTAG("List");
      for (int i = 0; i < this.cylinderList.size(); ++i)
        getCylinder(i).writeXML(paramXMLPrintWriter);
      paramXMLPrintWriter.end();
    }
    paramXMLPrintWriter.end();
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof Pie3D))
      return false;
    Pie3D localPie3D = (Pie3D)paramObject;
    if (!(Equals.equals(localPie3D.getProjection(), getProjection())))
      return false;
    if (localPie3D.getCylinderCount() != getCylinderCount())
      return false;
    for (int i = 0; i < localPie3D.getCylinderCount(); ++i)
      if (!(Equals.equals(localPie3D.getCylinder(i), getCylinder(i))))
        return false;
    return true;
  }
}